#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Jenkins数据上传主入口：自动采集Jenkins构建数据并上传到MySQL数据库
"""
from services.jenkins_service import JenkinsService
from utils.logger import sync_logger
from config.db_config import JENKINS_DB_CONFIG
import time

def main():
    """Jenkins数据上传主函数"""
    start_time = time.time()
    sync_logger.start_total_timer()
    
    try:
        # 初始化Jenkins服务，使用Jenkins专用数据库
        jenkins_service = JenkinsService(JENKINS_DB_CONFIG)
        
        # 执行数据同步
        jenkins_service.sync_jenkins_builds()
        
        total_time = time.time() - start_time
        sync_logger.log_info(f"Jenkins数据上传完成，总耗时: {total_time:.2f}秒")
    except Exception as e:
        sync_logger.log_error(f"Jenkins数据上传失败: {e}")
        total_time = time.time() - start_time
        sync_logger.log_info(f"Jenkins数据上传异常退出，总耗时: {total_time:.2f}秒")
    finally:
        sync_logger.stop_total_timer()

if __name__ == "__main__":
    main() 